//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Attribute attached to workflows and workflow parameters that allows
    /// setting both a name and a label. The name represents a quick, human
    /// readable description of the activity. Examples might include:
    /// -> 'Xml Parser'
    /// -> 'Web Page Downloader'
    /// -> 'Salinity Level Filter'
    /// 
    /// For a more complete description, please use the DescriptionAttribute.
    /// 
    /// The label property is meant as an optional name that is more terse
    /// and thus more presentable in a compact user interface environment.
    /// Thus for example 'Salinity Level Filter' might have as its label
    /// 'Salinity Filter' or even 'Salinity'.
    /// 
    /// For user interface considerations an expanded tooltip would likely
    /// use the name and description attributes, while a visual representation
    /// of an entire workflow would just use the label.
    /// 
    /// When no label is specified or when the label is empty, the name is
    /// returned when the Label property is querried. Thus it is not necessary
    /// to specify a label when you want the label to match the name.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)]
    public class NameAttribute : Attribute
    {
        private string name;
        private string label;

        /// <summary>
        /// Create a name attribute with just a Name property. The Label
        /// property will match the Name.
        /// </summary>
        public NameAttribute(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Create a name attribute with both a name and a label.
        /// </summary>
        /// <returns></returns>
        public NameAttribute(string name, string label)
        {
            this.name = name;
            this.label = label;
        }

        /// <summary>
        /// A short but descriptive name for the workflow or workflow activity.
        /// </summary>
        public string Name
        {
            get { return name; }
        }

        /// <summary>
        /// A short name for the workflow or workflow activity that is appropriate
        /// for use in small spaces within a graphical user interface.
        /// </summary>
        public string Label
        {
            get
            {
                if (String.IsNullOrEmpty(label))
                    return Name;
                return label;
            }
        }
    }
}
